/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.Entity;
import bpmn.Participant;
import bpmn.ParticipantType;
import bpmn.Role;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Participant</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.ParticipantImpl#getParticipantType <em>Participant Type</em>}</li>
 *   <li>{@link bpmn.impl.ParticipantImpl#getRoleRef <em>Role Ref</em>}</li>
 *   <li>{@link bpmn.impl.ParticipantImpl#getEntityRef <em>Entity Ref</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ParticipantImpl extends SupportingElementImpl implements Participant {
	/**
	 * The default value of the '{@link #getParticipantType() <em>Participant Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipantType()
	 * @generated
	 * @ordered
	 */
	protected static final ParticipantType PARTICIPANT_TYPE_EDEFAULT = ParticipantType.ROLE;

	/**
	 * The cached value of the '{@link #getParticipantType() <em>Participant Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipantType()
	 * @generated
	 * @ordered
	 */
	protected ParticipantType participantType = PARTICIPANT_TYPE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRoleRef() <em>Role Ref</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRoleRef()
	 * @generated
	 * @ordered
	 */
	protected Role roleRef;

	/**
	 * The cached value of the '{@link #getEntityRef() <em>Entity Ref</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEntityRef()
	 * @generated
	 * @ordered
	 */
	protected Entity entityRef;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ParticipantImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.PARTICIPANT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ParticipantType getParticipantType() {
		return participantType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParticipantType(ParticipantType newParticipantType) {
		ParticipantType oldParticipantType = participantType;
		participantType = newParticipantType == null ? PARTICIPANT_TYPE_EDEFAULT : newParticipantType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PARTICIPANT__PARTICIPANT_TYPE, oldParticipantType, participantType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Role getRoleRef() {
		return roleRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRoleRef(Role newRoleRef, NotificationChain msgs) {
		Role oldRoleRef = roleRef;
		roleRef = newRoleRef;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BpmnPackage.PARTICIPANT__ROLE_REF, oldRoleRef, newRoleRef);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRoleRef(Role newRoleRef) {
		if (newRoleRef != roleRef) {
			NotificationChain msgs = null;
			if (roleRef != null)
				msgs = ((InternalEObject)roleRef).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.PARTICIPANT__ROLE_REF, null, msgs);
			if (newRoleRef != null)
				msgs = ((InternalEObject)newRoleRef).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.PARTICIPANT__ROLE_REF, null, msgs);
			msgs = basicSetRoleRef(newRoleRef, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PARTICIPANT__ROLE_REF, newRoleRef, newRoleRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity getEntityRef() {
		return entityRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEntityRef(Entity newEntityRef, NotificationChain msgs) {
		Entity oldEntityRef = entityRef;
		entityRef = newEntityRef;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BpmnPackage.PARTICIPANT__ENTITY_REF, oldEntityRef, newEntityRef);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEntityRef(Entity newEntityRef) {
		if (newEntityRef != entityRef) {
			NotificationChain msgs = null;
			if (entityRef != null)
				msgs = ((InternalEObject)entityRef).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.PARTICIPANT__ENTITY_REF, null, msgs);
			if (newEntityRef != null)
				msgs = ((InternalEObject)newEntityRef).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - BpmnPackage.PARTICIPANT__ENTITY_REF, null, msgs);
			msgs = basicSetEntityRef(newEntityRef, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.PARTICIPANT__ENTITY_REF, newEntityRef, newEntityRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case BpmnPackage.PARTICIPANT__ROLE_REF:
				return basicSetRoleRef(null, msgs);
			case BpmnPackage.PARTICIPANT__ENTITY_REF:
				return basicSetEntityRef(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.PARTICIPANT__PARTICIPANT_TYPE:
				return getParticipantType();
			case BpmnPackage.PARTICIPANT__ROLE_REF:
				return getRoleRef();
			case BpmnPackage.PARTICIPANT__ENTITY_REF:
				return getEntityRef();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.PARTICIPANT__PARTICIPANT_TYPE:
				setParticipantType((ParticipantType)newValue);
				return;
			case BpmnPackage.PARTICIPANT__ROLE_REF:
				setRoleRef((Role)newValue);
				return;
			case BpmnPackage.PARTICIPANT__ENTITY_REF:
				setEntityRef((Entity)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.PARTICIPANT__PARTICIPANT_TYPE:
				setParticipantType(PARTICIPANT_TYPE_EDEFAULT);
				return;
			case BpmnPackage.PARTICIPANT__ROLE_REF:
				setRoleRef((Role)null);
				return;
			case BpmnPackage.PARTICIPANT__ENTITY_REF:
				setEntityRef((Entity)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.PARTICIPANT__PARTICIPANT_TYPE:
				return participantType != PARTICIPANT_TYPE_EDEFAULT;
			case BpmnPackage.PARTICIPANT__ROLE_REF:
				return roleRef != null;
			case BpmnPackage.PARTICIPANT__ENTITY_REF:
				return entityRef != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (ParticipantType: ");
		result.append(participantType);
		result.append(')');
		return result.toString();
	}

} //ParticipantImpl
